/*
 * Copyright (c) 2010 Vadim Zhukov <persgray@gmail.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */


#include "common.h"

#ifdef __linux__
#define __BSD_VISIBLE	1
#include "../compat/endian.h"
#else
#include <sys/endian.h>
#endif

/* FreeBSD compat */
#ifndef betoh64
#define betoh64(x) be64toh(x)
#endif

#include <stdint.h>
#include <time.h>

#include "timestamp.h"


/*
 * Those functions packs host's time_t value into uint64_t that we use for
 * for timestamps on the wire and unpacks the value back. Actually, the value
 * may get only bigger now after packing, but nevermind. :)
 * 
 * Host-to-network byte order swap is done as a bonus.
 */

uint64_t
timestamp_pack(time_t t) {
	return htobe64(t);
}

time_t
timestamp_unpack(uint64_t t64) {
	return (time_t)betoh64(t64);
}
